package quizman.mappers;
import java.sql.ResultSet;

import quizman.domain.Question;
import quizman.tdg.MultipleChoiceTDG;

/**
 * 
 */

/**
 * @author Team0i
 *
 */
public class ShortAnswerMapper {
	public static String find(String questionName) throws Exception {
		try {
			ResultSet rs = MultipleChoiceTDG.find(questionName);
			if(!rs.next()) return null;
			String text = rs.getString("Answer_Text");
			return text;
		} catch (Exception e) {
			String msg = "Error in ShortAnswer.find";
			throw new Exception(msg, e);
		}
	}
	
	public static void insert(Question q, String text) throws Exception {
		try {
			MultipleChoiceTDG.insert(q.getName(), text, true);
		} catch (Exception e) {
			String msg = "Error in ShortAnswer.insert";
			throw new Exception(msg,e);
		}
	}
	
	public static void update(Question q, String answer, String newAnswer) throws Exception {
		try {
			MultipleChoiceTDG.update(q.getName(), answer, newAnswer, true);
		} catch (Exception e) {
			String msg = "Error in ShortAnswer.update";
			throw new Exception(msg,e);
		}
	}
	
	public static void delete(Question q) throws Exception {
		try {
			MultipleChoiceTDG.deleteAll(q.getName());
		} catch (Exception e) {
			String msg = "Error in ShortAnswer.delete";
			throw new Exception(msg,e);
		}
	}
}
